//
//  BaseTabBarController.m
//  EggSteward
//
//  Created by 王道林 on 16/8/27.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "BaseTabBarController.h"
#import "BaseNavigationController.h"
#import "HomeViewController.h"
#import "CommentViewController.h"
#import "LogonViewController.h"
#import "SetViewController.h"
#import "AddressListViewController.h"
#import "MarketViewController.h"
#import "SetLogonViewController.h"

@interface BaseTabBarController ()

@end

@implementation BaseTabBarController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.viewControllers = [self createSubVC];
        [self setUp];
    }
    return self;
}

- (NSMutableArray<UIViewController *> *)createSubVC
{
    NSMutableArray *VCArr = [NSMutableArray array];
    
    HomeViewController *HomeVC = [[HomeViewController alloc] init];
    BaseNavigationController *Navi1 = [[BaseNavigationController alloc] initWithRootViewController:HomeVC];
    HomeVC.navigationItem.title = @"鸡蛋头条";
    HomeVC.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    HomeVC.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.202 green:0.851 blue:0.364 alpha:1.000];
    HomeVC.navigationController.navigationBar.translucent = NO;
    Navi1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"1_s"] tag:100];
    [VCArr addObject:Navi1];
    
    MarketViewController *marketVC = [[MarketViewController alloc] init];
    BaseNavigationController *Navi2 = [[BaseNavigationController alloc] initWithRootViewController:marketVC];
    marketVC.navigationItem.title = @"价格行情";
    marketVC.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.202 green:0.851 blue:0.364 alpha:1.000];
    marketVC.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    marketVC.navigationController.navigationBar.translucent = NO;
    Navi2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"价格行情" image:[UIImage imageNamed:@"2"] tag:200];
    
    [VCArr addObject:Navi2];
    
    
        SetViewController *setVc = [[SetViewController alloc] init];
        BaseNavigationController *Navi4 = [[BaseNavigationController alloc] initWithRootViewController:setVc];
    // 移除观察者
    [[NSNotificationCenter defaultCenter] removeObserver:Navi4 name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:Navi4 name:@"night" object:nil];
    
        setVc.navigationItem.title = @"设置";
        setVc.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.202 green:0.851 blue:0.364 alpha:1.000];
        setVc.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];       
        Navi4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"3"] tag:300];
        [VCArr addObject:Navi4];
    
    
    return VCArr;
}



- (void)setUp
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(night:) name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil userInfo:nil];
    } else
    {
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
    
}
- (void)night:(NSNotification *)sender
{
    self.tabBar.barTintColor = [UIColor colorWithWhite:0.782 alpha:1.000];
}
- (void)dayTime:(NSNotification *)sender
{
    self.tabBar.barTintColor = [UIColor whiteColor];
}





- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
